package weekMatch.two_101;

public class LeeCode_02 {
    public static void main(String[] args) {
        System.out.println(maximumCostSubstring("adaa", "d", new int[]{-1000}));
        System.out.println(maximumCostSubstring("abc", "abc", new int[]{-1,-1,-1}));
    }
    private static int maximumCostSubstring(String s, String chars, int[] vals) {
        int res = 0;
        int sum = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (chars.contains(c + "")){
                sum += vals[chars.indexOf(c)];
            }else {
                sum += c - 'a' + 1;
            }
            if (sum < 0){
                sum = 0;
                continue;
            }
            res = Math.max(sum, res);
        }
        return res;
    }
}
